/**
 * Copyright © 2021-2025 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.invoice.qrcode.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.invoice.qrcode.service.dto.YxfpQrcodeDTO;
import com.jeeplus.invoice.qrcode.domain.YxfpQrcode;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 二维码管理MAPPER接口
 * @author 张如利
 * @version 2022-01-20
 */
public interface YxfpQrcodeMapper extends BaseMapper<YxfpQrcode> {

    /**
     * 根据id获取二维码
     * @param id
     * @return
     */
    YxfpQrcodeDTO findById(String id);

    /**
     * 获取二维码列表
     *
     * @param queryWrapper
     * @return
     */
    IPage <YxfpQrcodeDTO> findList(Page <YxfpQrcodeDTO> page, @Param(Constants.WRAPPER) QueryWrapper queryWrapper);

    /**
     * 根据merchantId获取二维码
     * @param merchantId
     * @return
     */
    @Select("select * from yxfp_qrcode where merchant_id = #{0}")
    YxfpQrcodeDTO findByMerchantId(String merchantId);

    /**
     * 商家绑定二维码
     * @param merchantId
     * @param qrcodeId
     */
    @Update("update yxfp_qrcode set bind_state = '1', merchant_id = #{merchantId} where id = #{qrcodeId}")
    void bindingQrcode(String merchantId,String qrcodeId);

    /**
     * 商家解除绑定二维码
     * @param qrcodeId
     */
    @Update("update yxfp_qrcode set merchant_id = null,bind_state='0' where id = #{0}")
    void unBindingQrcode(String qrcodeId);

    /**
     * 根据二维码内容查询商户ID
     * @param content
     */
    YxfpQrcodeDTO getMerchantIdByContent(String content);
}
